package com.linkage.educloud.ah.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.linkage.educloud.ah.R;
import com.linkage.educloud.ah.bean.BrandAreaBean;
import com.linkage.educloud.ah.util.ImageLoader;
import com.zzhou.common.library.util.ToastShow;

import java.util.List;

/**
 * Created by Mr'Tang on 2018/12/19.
 */

public class BrandAreaAdapter extends XRecyclerView.Adapter<BrandAreaAdapter.ViewHolder> {
    private List<BrandAreaBean> mlist;
    private Context mcontext;

    public BrandAreaAdapter(Context context, List<BrandAreaBean> datas) {
        this.mcontext = context;
        this.mlist = datas;
    }

    public void addAll(List<BrandAreaBean> data) {
        mlist = data;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_topic_group_list, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        BrandAreaBean info = mlist.get(position);
        ImageLoader.loadImg(mcontext, info.getResicon(), holder.item_brandarea_img);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastShow.show(mcontext, "待添加");
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView item_brandarea_img;

        public ViewHolder(View convertView) {
            super(convertView);
            item_brandarea_img = convertView.findViewById(R.id.item_brandarea_img);
        }
    }
}
